package cn.sc.allinpay.allfavour.business.sale;

import android.os.Bundle;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.pai.common.adapter.BaseRecyAdapter;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.DecorationVert;
import cn.sc.allinpay.allfavour.business.common.adapter.SaleCouponAdapter;
import cn.sc.allinpay.allfavour.business.common.adapter.CouponTypeAdapter;
import cn.sc.allinpay.allfavour.business.common.data.SaleCouponData;


/**
 * activity 售券
 * author：pany
 * on 2017/12/1 11:14
 */
public class SaleActivity extends BaseActivity<SaleContract.View, SaleContract.Presenter>
        implements SaleContract.View, AdapterView.OnItemSelectedListener {

    @BindView(R.id.spType)
    AppCompatSpinner spType;
    @BindView(R.id.recycler)
    RecyclerView recycler;

    private SaleCouponAdapter saleAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_sale;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("售券");
    }

    @Override
    protected SaleContract.Presenter bindPresenter() {
        return new SalePresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        spType.setOnItemSelectedListener(this);
        recycler.addItemDecoration(new DecorationVert(this, R.dimen.margin_common, R.dimen.margin_common));
        recycler.setLayoutManager(new LinearLayoutManager(this));// 列表布局
        saleAdapter = new SaleCouponAdapter();
        recycler.setAdapter(saleAdapter);
        saleAdapter.setOnAdapterListener(new BaseRecyAdapter.OnAdapterListener<SaleCouponData>() {
            @Override
            public void onItemClick(View view, int position, SaleCouponData data) {
                presenter.startSaleDetailActivity(data);
            }
        });
    }

    @Override
    public void setTypeAdapter(List<String> list) {
        spType.setAdapter(new CouponTypeAdapter(this, list));
    }

    @Override
    public int getType() {
        return spType.getSelectedItemPosition();
    }

    @Override
    public void saleAdapterChange(List<SaleCouponData> datas) {
        saleAdapter.change(datas);
    }

    @OnClick(R.id.btnTrans)
    public void click(View v) {
        presenter.startSaleTransActivity();
    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        presenter.changeSaleAdapterByType();
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }
}
